package top.fengyulou.xiaofeng.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.fengyulou.xiaofeng.common.UserUtils;
import top.fengyulou.xiaofeng.common.UuidUtil;
import top.fengyulou.xiaofeng.domain.Label;
import top.fengyulou.xiaofeng.dto.LabelDto;
import top.fengyulou.xiaofeng.dto.QuestionDto;
import top.fengyulou.xiaofeng.dto.UserExamPaperDto;
import top.fengyulou.xiaofeng.dto.UserExamQuestionDto;
import top.fengyulou.xiaofeng.mapper.LabelMapper;
import top.fengyulou.xiaofeng.mapper.UserExamQuestionMapper;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @ClassName LabelService
 * @Description TODO
 * @Author qwer
 * @Date 2021/8/22 1:54
 * @Version 1.0
 */
@Service
public class UserExamQuestionService {

    @Resource
    private UserExamQuestionMapper userExamQuestionMapper;
    @Resource
    private UserExamPaperService userExamPaperService;

    public void insertBatch(List<UserExamQuestionDto> list) {
        userExamQuestionMapper.insertBatch(list);
    }

    public List<QuestionDto> list(UserExamQuestionDto userExamQuestionDto) {
        return userExamQuestionMapper.list(userExamQuestionDto);
    }

    public List<QuestionDto> parseList(UserExamQuestionDto userExamQuestionDto) {
        return userExamQuestionMapper.parseList(userExamQuestionDto);
    }

    public void update(UserExamQuestionDto userExamQuestionDto) {
        userExamQuestionDto.setLastUpdateUserId(userExamQuestionDto.getCurrentUserId());
        userExamQuestionDto.setUpdateTime(new Date());
        userExamQuestionMapper.update(userExamQuestionDto);
    }

    @Transactional
    public void updateScore(UserExamQuestionDto userExamQuestionDto) {
        //修改试题分数
        update(userExamQuestionDto);
        //修改试卷分数
        UserExamPaperDto userExamPaperDto = new UserExamPaperDto();
        userExamPaperDto.setId(userExamQuestionDto.getUserPaperId());
        userExamPaperDto.setCurrentUserId(userExamQuestionDto.getCurrentUserId());
        userExamPaperDto.setStatus(1);
        userExamPaperService.updateScore(userExamPaperDto);
    }
}

